// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CXFormsElementSelectMany.
//   $Id$
#ifndef SELECT_UI_INCLUDED
#define SELECT_UI_INCLUDED 1
#pragma once

#include "FormControlInputUI.h"
#include "select.h"

#include "parse.h"
class CXFormsElementSelection 
	: public CXFormsElementFormControlInput
	,public IUISelection
{
public:

public:
	CXFormsElementSelection();
	virtual ~CXFormsElementSelection();

	virtual CImpl* CreateImpl();
	virtual CXFormsParse* CreateParse(CImpl* pImpl);
	virtual HRESULT put_value(BSTR bsValue);
	virtual HRESULT put_alert(const BSTR bsValue);
	virtual HRESULT put_caption(const BSTR bsCaption);
	STDMETHOD(get_CurrentValue)(BSTR *psCurrentValue);
//	virtual HRESULT handleEvent(DISPID eventID,VARIANT* pvarResult,DISPPARAMS* pdispparams);
protected:
	virtual HRESULT getUI(CComBSTR &sHtml);
	bool m_bMultiselectAllowed;

	/////////////////////////////////////////
	//		BEGIN: interface IUISelection
	/////////////////////////////////////////
public:
	virtual HRESULT AddItem
	(
		const BSTR sId,
		const BSTR sCaption,
		const BSTR sValue,
		const BSTR sInsideId,
		const bool bClear
	);

	virtual HRESULT RemoveItem
	(
		const BSTR /*id*/,
		const long /*index = 0*/
	){return S_OK;};

	virtual HRESULT put_ItemCaption
	(
		const BSTR id,
		const BSTR caption,
		const unsigned long index = 0
	);
	virtual HRESULT put_ItemValue
	(
		const BSTR id,
		const BSTR value,
		const unsigned long index = 0
	);
	virtual HRESULT put_ItemAlert
	(
		const BSTR id,
		const BSTR alert,
		const unsigned long index = 0
	);
	/////////////////////////////////////////
	//		END: interface IUISelection
	/////////////////////////////////////////
protected:
	HRESULT SetScriptContext();
private:
	DISPID m_didAddItem;
	DISPID m_didSetContext;
	CComBSTR m_sLabel;
};

class CXFormsElementSelectMany : public CXFormsElementSelection
{
public:
	CXFormsElementSelectMany();
	virtual ~CXFormsElementSelectMany();

private:
	//Manipulating/inspecting the value of different
	//	representations of a selection.  These are called
	//	by put_value and get_value following a check against 
	//	m_eRepresentation.

//	virtual HRESULT put_valueToTree(BSTR sVal);

//	virtual HRESULT get_valueFromTree(BSTR * psVal);
	


};

class CXFormsElementSelectOne : public CXFormsElementSelection
{
public:
	CXFormsElementSelectOne();
	virtual ~CXFormsElementSelectOne();

	virtual CImpl* CreateImpl();
	virtual CXFormsParse* CreateParse(CImpl* pImpl);
	virtual HRESULT ElementReady();
protected:
	virtual HRESULT handleEvent(CComBSTR& sEventName, IHTMLEventObj2 * pEventObject,VARIANT * pvarResult);
	virtual HRESULT detachEvents();
private:
	//Manipulating/inspecting the value of different
	//	representations of a selection.  These are called
	//	by put_value and get_value following a check against 
	//	m_eRepresentation.
	HRESULT resize();
	DISPID m_didResize;
//	virtual HRESULT put_valueToTree(BSTR sVal);
//	virtual HRESULT get_valueFromTree(BSTR * psVal);
};
#endif